import {fromJS} from "immutable";
import * as types from './type'

const defaultData = fromJS({
    userid: "",
    uname: "",
    email: "",
    phone: "",
    sex: "",
    loginTime: "",
    onlineId: "",
    onlineName: "",
    onlineLevel: "",
    images: "",
    onlineIntegral: "",
    onlineText: "",
    token: "",
    timeout: "",
    isAdmin: "",
    statusId: "",
    createDate: "",
    finalDare: "",
    jcoins: "",
    isVip: 0,
    vipExpireDate: null,
    vipType: 0
})
const user = (state = defaultData, action) => {
    const newVal = action.value;
    switch (action.type) {
        case types.INIT_USER_INFO:
            return state.mergeDeep(newVal);
        case types.USER_CLEAR_BOTH:
            let resetData = defaultData.toJS();
            Object.keys(resetData).forEach(key => {
                resetData[key] = "";
            })
            return state.mergeDeep(resetData);
        case types.UPDATE_USER_IMAGE:
            return state.set('images', newVal);
        case types.REFRESH_TOKEN:
            return state.set('token', newVal);
        default:
            return state;
    }
}
export default user;
